﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SLogo.Compile
{
    /// <summary>
    /// 代表命令的参数
    /// </summary>
    class Agument
    {
        /// <summary>
        /// 参数类型的枚举
        /// </summary>
        public enum ArgumentType
        {
            String,
            Number,
            Variable
        }
        /// <summary>
        /// 参数类型
        /// </summary>
        public ArgumentType TheType { get; set; }
        /// <summary>
        /// 字符串类型变量的值
        /// </summary>
        public String StringValue
        {
            get
            {
                return TheType == ArgumentType.String ? _stringValue : null;
            }
            set { _stringValue = value; }
        }
        //真正存储值的字符串
        private String _stringValue;
        /// <summary>
        /// 数值类型变量的值
        /// </summary>
        public double NumberValue
        {
            get
            {
                return TheType == ArgumentType.Number ? _numberValue : Double.NaN;
            }
            set { _numberValue = value; }
        }
        //真正存储值的数值变量
        private double _numberValue;
        /// <summary>
        /// 数值类型变量的值
        /// </summary>
        public Variable VariableValue
        {
            get
            {
                return TheType == ArgumentType.Variable ? _variableValue : null;
            }
            set { _variableValue = value; }
        }
        //真正存储值的数值变量
        private Variable _variableValue;

        /// <summary>
        /// 初始化为字符串
        /// </summary>
        /// <param name="value">字符串的值</param>
        public Agument(String value)
        {
            StringValue = value;
            TheType = ArgumentType.String;
        }
        /// <summary>
        /// 初始化为数值
        /// </summary>
        /// <param name="value">数值</param>
        public Agument(double value)
        {
            NumberValue = value;
            TheType = ArgumentType.Number;
        }
        /// <summary>
        /// 初始化为变量
        /// </summary>
        /// <param name="value">变量</param>
        public Agument(ref Variable value)
        {
            VariableValue = value;
            TheType = ArgumentType.Variable;
        }
    }
}
